//
//  ZBYTabBarViewController.swift
//  新浪微博
//
//  Created by zby on 16/2/25.
//  Copyright © 2016年 zby. All rights reserved.
//

import UIKit

class ZBYTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //使用KVC给只读属性赋值
        let tabbar = ZBYTabBar()
        
        setValue(tabbar, forKey: "tabBar")
        
        //添加控制器
        addChildViewController()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
    }
    
    //重载
    func addChildViewController() {
        addChildViewController(ZBYHomeViewController(), title: "首页", image: "tabbar_home")
        addChildViewController(ZBYMessageViewController(), title: "消息", image: "tabbar_message_center")
        addChildViewController(ZBYFindViewController(), title: "发现", image: "tabbar_discover")
        addChildViewController(ZBYSettingViewController(), title: "设置", image: "tabbar_profile")
    }

    //重载
    func addChildViewController(childController: UIViewController,title: String,image: String) {
        
        //设置文字
        childController.title = title
        
        //设置图片
        childController.tabBarItem.image = UIImage(named: image)
        childController.tabBarItem.selectedImage = UIImage(named: "\(image)_highlighted")
        
        //设置渲染色
        UITabBar.appearance().tintColor = UIColor.orangeColor()

        //包装成子控制器
        addChildViewController(UINavigationController(rootViewController: childController))
    }

}









